<?php
	extract($_REQUEST, EXTR_PREFIX_ALL|EXTR_REFS, 'v');
	$shpsn=$v_shpsn;
	$pmcode=$v_pmcode;
	if($pmcode<>""){
				$crtf="select * from shoplist_dist where sn = '$shpsn'";
				$crtresf=mysql_query($crtf,$db);
				$crf=mysql_fetch_array($crtresf);
				$orgprice=$crf['org_price'];
                $csnn = $crf['csnNumber'];
                $ssnn = $crf['ssnNumber'];
                $dsnn = $crf['dsnNumber'];
                $catalog = $crf['catNo'];
													//For Finding Promotion Code Discounts, only valid if no other discounts found first
													$findpromo1="select * from distributor_promo where promo_code='$pmcode' and csn='$csnn' and ssn='$ssnn' and dsn='$dsnn' and catNo='$catalog'";
													$resultingpromo1=mysql_query($findpromo1,$db);
													$rowp1=mysql_num_rows($resultingpromo1);
													
													$findpromo2="select * from distributor_promo where promo_code='$pmcode' and csn='$csnn' and ssn='$ssnn' and dsn='$dsnn' and catNo='0'";
													$resultingpromo2=mysql_query($findpromo2,$db);
													$rowp2=mysql_num_rows($resultingpromo2);
													
													$findpromo3="select * from distributor_promo where promo_code='$pmcode' and csn='$csnn' and ssn='$ssnn' and dsn='0' and catNo='0'";
													$resultingpromo3=mysql_query($findpromo3,$db);
													$rowp3=mysql_num_rows($resultingpromo3);
													
													$findpromo4="select * from distributor_promo where promo_code='$pmcode' and csn='$csnn' and ssn='0' and dsn='0' and catNo='0'";
													$resultingpromo4=mysql_query($findpromo4,$db);
													$rowp4=mysql_num_rows($resultingpromo4);
													
													$findpromo5="select * from distributor_promo where promo_code='$pmcode' and csn='0';";
													$resultingpromo5=mysql_query($findpromo5,$db);
													$rowp5=mysql_num_rows($resultingpromo5);
													if($rowp1>0){
														$rf = mysql_fetch_array($resultingpromo1);
														$discountper=$rf['percentage_off'];
														$discountamt=$orgprice*$discountper;
														$price=$orgprice-$discountamt;
													}elseif($rowp2>0){
														$rf = mysql_fetch_array($resultingpromo2);
														$discountper=$rf['percentage_off'];
														$discountamt=$orgprice*$discountper;
														$price=$orgprice-$discountamt;
													}elseif($rowp3>0){
														$rf = mysql_fetch_array($resultingpromo3);
														$discountper=$rf['percentage_off'];
														$discountamt=$orgprice*$discountper;
														$price=$orgprice-$discountamt;
													}elseif($rowp4>0){
														$rf = mysql_fetch_array($resultingpromo4);
														$discountper=$rf['percentage_off'];
														$discountamt=$orgprice*$discountper;
														$price=$orgprice-$discountamt;
													}elseif($rowp5>0){
														$rf = mysql_fetch_array($resultingpromo5);
														$discountper=$rf['percentage_off'];
														$discountamt=$orgprice*$discountper;
														$price=$orgprice-$discountamt;
													}else{
														$discountper=0.0;
														$discountamt=0.00;
														$price=$orgprice;
													}
			$sql="update shoplist_dist set discount_percent='$discountper',discount_amount='$discountamt',price='$price' where sn = '$shpsn'";
			$result = mysql_query($sql,$db);
	}
	
	$ssid=$_SESSION['id'];
			$sql="update shoplist_dist set quantity='$qtychg', promotioncode = '$pmcode' where sn = '$shpsn'";
			$result = mysql_query($sql,$db);
	$cart=1;
?>
